#ifndef _SERIAL5_H_
#define _SERIAL5_H_

#include <stdio.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <pthread.h>

#include <dirent.h>

//gec6818串口
#define 	USART1		"/dev/ttySAC1"
#define 	USART2		"/dev/ttySAC2"
#define 	USART3		"/dev/ttySAC3"


#define GEC6818_BEEP_ON  _IO('B', 0)
#define GEC6818_BEEP_OFF _IO('B', 1)

extern unsigned char WBuf[128], RBuf[128];//写入与读取RFID数据的缓冲区
extern struct timeval timeout;//时间结构体
extern volatile unsigned int cardid ;//IC卡卡号变量
extern unsigned char KEY_BUF[6];//验证码
extern unsigned char DataWriteBuf[16];//写入IC卡的数据
extern unsigned char DataReadBuf[16];//从IC卡中读取的数据

//初始化串口设置---波特率9600，无数据位8位，无奇偶校验位，停止位1位
void init_tty(int fd);

/*计算校验和*/
unsigned char CalBCC(unsigned char *buf, int n);

int Picc_request(int fd);//发送A命令----请求IC卡
int Picc_getID(int fd);/*防碰撞，获取范围内最大ID*/
int Picc_select(int fd);//选择IC卡
int Picc_Key(int fd,int sector,unsigned char KeyAB);//验证密钥
int PiccWrite(int fd,unsigned char sector,char *str,int num );//向扇区中写入数据
int PiccRead(int fd,unsigned char sector);

#endif